<%
function getSysTemplet(skinCfgPath)
        on error resume next
        dim dir, fso, file, cfgXML, encoding, encoding2, tmpltFile, tmpltFile2
        dim template_name, template_desc, template_code, template_code2, dateLastModified
        dir = MISSLOG_ROOT &  mid(skinCfgPath, 1, instrrev(skinCfgPath,"/"))
        set cfgXML = Server.CreateObject("Microsoft.XMLDOM")
        cfgXML.async=False
        cfgXML.load(Server.MapPath(MISSLOG_ROOT & skinCfgPath))
        if cfgXML.parseError.errorCode = 0 then
            template_name  =  cfgXML.documentElement.selectSingleNode("name").text
            template_desc  =  cfgXML.documentElement.selectSingleNode("description").text

            encoding =  cfgXML.documentElement.selectSingleNode("pages/index/charset").text
            tmpltFile = cfgXML.documentElement.selectSingleNode("pages/index/templet").text
            encoding2 =  cfgXML.documentElement.selectSingleNode("pages/detail/charset").text
            tmpltFile2 = cfgXML.documentElement.selectSingleNode("pages/detail/templet").text
            
            Dim objStream
            Set objStream = Server.CreateObject("ADODB.Stream")
            objStream.Type = 2
            objStream.Mode  = 3
            objStream.Open
            objStream.LoadFromFile(Server.MapPath(dir & tmpltFile))
            objStream.Charset = encoding
            objStream.Position = 2
            template_code = objStream.ReadText
            objStream.Close
            Set objStream = nothing

            Set objStream = Server.CreateObject("ADODB.Stream")
            objStream.Type = 2
            objStream.Mode  = 3
            objStream.Open
            objStream.LoadFromFile(Server.MapPath(dir & tmpltFile2))
            objStream.Charset = encoding2
            objStream.Position = 2
            template_code2 = objStream.ReadText
            objStream.Close
            Set objStream = nothing
            
            '获取模板文件最后修改时间
            set fso=Server.CreateObject("Scripting.FileSystemObject")
            set file=fso.GetFile(Server.MapPath(dir & tmpltFile))
            dateLastModified = file.DateLastModified
            set file = nothing
            set file=fso.GetFile(Server.MapPath(dir & tmpltFile2))
            if dateLastModified < file.DateLastModified then
                dateLastModified = file.DateLastModified
            end if
            set file = nothing
            set fso = nothing
            
        end if
        set cfgXML = nothing
        on error goto 0
        
        dim skinData
        redim skinData(4)
        skinData(0) = template_name
        skinData(1) = template_desc
        skinData(2) = template_code
        skinData(3) = template_code2
        skinData(4) = dateLastModified
        getSysTemplet = skinData
end function


sub writeSysTemplets0(isCreateFrom)
%>

<a name="#pageno_folders"></a>
<table border=1 cellspacing=0  style="border-collapse: collapse" bordercolor="gray">
  <tr  >
    <td >选择</td><td>模板名</td><td>描述</td><td>制作日期</td><td>制作人</td><td>预览图&nbsp;</td>
  </tr>
<%
    'on error resume next
    dim skinsPath, fso, skinsFolder, folders, subfolder, cfgXML, pageno_folders, totalCount,pageSize,i,URL
    skinsPath = Server.mapPath(MISSLOG_ROOT & "/skins")
    
    set cfgXML = Server.CreateObject("Microsoft.XMLDOM")
    cfgXML.async=False
    
    set fso = createobject("Scripting.FileSystemObject")
    set skinsFolder = fso.getfolder(skinsPath)
    set folders = skinsFolder.subfolders
    
    totalCount = folders.count
    pageSize = 5
    i = 0
    
    pageno_folders = request("pageno_folders")
    if pageno_folders<>"" then
    	pageno_folders = clng(pageno_folders)
    else
    	pageno_folders = 1
	end if
	
	totalCount = 0
	for each subfolder in folders 
	    cfgXML.load(skinsPath & "\" & subfolder.name & "\config.xml")
	    if cfgXML.parseError.errorCode = 0 then
	    	totalCount = totalCount + 1
	    end if
	next
	
    for each subfolder in folders 
	    if i > pageno_folders * pageSize - 1 then
	        exit for
	    end if
        
	    cfgXML.load(skinsPath & "\" & subfolder.name & "\config.xml")
	    if cfgXML.parseError.errorCode = 0 then
        	if i >= pageSize * (pageno_folders-1) then
%>  
  <tr>
    <td><input type=radio <% if isCreateFrom then %> name="parent_id" <% else %> name="template_id" <% end if %> value="<%="/skins/" & subfolder.name & "/config.xml"%>"></td>
    <td nowrap><%=cfgXML.documentElement.selectSingleNode("name").text %>&nbsp;</td>
    <td><%=cfgXML.documentElement.selectSingleNode("description").text %>&nbsp;</td>
    <td nowrap><%=cfgXML.documentElement.selectSingleNode("date").text%>&nbsp;</td>
    <td><%=cfgXML.documentElement.selectSingleNode("author").text%>&nbsp;</td>
    <td><a href="<%=MISSLOG_ROOT & "/skins/" & subfolder.name & "/" & cfgXML.documentElement.selectSingleNode("image/large").text%>" target="_blank">
        <img src="<%=MISSLOG_ROOT & "/skins/" & subfolder.name & "/" & cfgXML.documentElement.selectSingleNode("image/small").text%>" border=0></a></td>
  </tr>
<%
	        end if
     		i = i + 1
	    else
%>
  <!--<tr><td colspan=6>Skin <%=subfolder.name%> config.xml load error: <%=cfgXML.parseError.reason%></td></tr>-->
<%
	    end if
    next
    set subfolder = nothing
    set folders = nothing
    set skinsFolder = nothing
    set fso = nothing
    set cfgXML = nothing
    'on error goto 0
%>  
</table>    
<div align=center>
  <%=htmlPageLink2(pageno_folders, pageSize, totalCount, url, "pageno_folders")%>
</div>  
<%
end sub
%>

<%
sub writeSysTemplets(isCreateFrom)
%>

<a name="#pageno_folders"></a>
<table border=0 cellspacing=0 cellpadding=10 >
<%
    'on error resume next
    dim skinsPath, fso, skinsFolder, folders, subfolder, cfgXML, pageno_folders, totalCount,pageSize,i,URL
    skinsPath = Server.mapPath(MISSLOG_ROOT & "/skins")
    
    set cfgXML = Server.CreateObject("Microsoft.XMLDOM")
    cfgXML.async=False
    
    set fso = createobject("Scripting.FileSystemObject")
    set skinsFolder = fso.getfolder(skinsPath)
    set folders = skinsFolder.subfolders
    
    totalCount = folders.count
    pageSize = 9
    i = 0
    
    pageno_folders = request("pageno_folders")
    if pageno_folders<>"" then
    	pageno_folders = clng(pageno_folders)
    else
    	pageno_folders = 1
	end if
	
	totalCount = 0
	for each subfolder in folders 
	    cfgXML.load(skinsPath & "\" & subfolder.name & "\config.xml")
	    if cfgXML.parseError.errorCode = 0 then
	    	totalCount = totalCount + 1
	    end if
	next
	
    for each subfolder in folders 
	    if i > pageno_folders * pageSize - 1 then
	        exit for
	    end if
        
	    cfgXML.load(skinsPath & "\" & subfolder.name & "\config.xml")
	    if cfgXML.parseError.errorCode = 0 then
        	if i >= pageSize * (pageno_folders-1) then
        	    if i mod 3 = 0 then 
        	        if i>0 then
        	          response.write "</tr>" & vbCrLf
        	        end if
        	        response.write "<tr>" & vbCrLf
        	    end if
%>  
  
    <td  valign=bottom style="font-size:9pt">
        <a  
          title="点击查看大图"
          href="<%=MISSLOG_ROOT & "/skins/" & subfolder.name & "/" & cfgXML.documentElement.selectSingleNode("image/large").text%>" target="_blank">
        <img 
          alt="<%=cfgXML.documentElement.selectSingleNode("name").text %>"
          src="<%=MISSLOG_ROOT & "/skins/" & subfolder.name & "/" & cfgXML.documentElement.selectSingleNode("image/small").text%>" border=0></a>
          
        <br>
        <input type=radio <% if isCreateFrom then %> name="parent_id" <% else %> name="template_id" <% end if %> value="<%="/skins/" & subfolder.name & "/config.xml"%>">
        <%=cfgXML.documentElement.selectSingleNode("name").text %> 作者：<%=cfgXML.documentElement.selectSingleNode("author").text%>
        <br>
    </td>
<%
	        end if
     		i = i + 1
	    else
%>
  <!--<tr><td colspan=6>Skin <%=subfolder.name%> config.xml load error: <%=cfgXML.parseError.reason%></td></tr>-->
<%
	    end if
    next
    set subfolder = nothing
    set folders = nothing
    set skinsFolder = nothing
    set fso = nothing
    set cfgXML = nothing
    'on error goto 0
%>  
</table>    
<div align=center>
  <%=htmlPageLink2(pageno_folders, pageSize, totalCount, url, "pageno_folders")%>
</div>  
<%
end sub
%>